package com.jt.controller;

import com.jt.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

@Controller
public class AddUserController {
    @RequestMapping("/addUser")
    public String addUser(User user){//此类必须实现get，set方法
        System.out.println("收到参数：user="+user);
        return "success";
    }

//    @RequestMapping("/addUser")
//    public String addHobbys(Integer id,String name,String[] hobby){//如果参数时最后一个，可以用可变参数String...
//        System.out.println("收到参数：id="+id+",name="+name+",hobby="+ Arrays.toString(hobby));
//        return "success";
//    }


    //@RequestParam 必填项，加属性required=true，则必填不能为null，一般默认为true   加属性defaultValue=""，为null时填默认值
//    @RequestMapping("/addUser")
//    public String addUserParam(@RequestParam(value = "id") Integer id,String name){//自动调request.getParameter()方法
//        System.out.println("收到参数：id="+id+",name="+name);
//        return "success";
//    }


//    @RequestMapping("/addUser")
//    public String addUser(Integer id,String name){//自动调request.getParameter()方法
//        System.out.println("收到参数：id="+id+",name="+name);
//        return "success";
//    }


//    @RequestMapping("/addUser")
//    public String addUser(HttpServletRequest request, HttpServletResponse response){
//        String id = request.getParameter("id");
//        String name = request.getParameter("name");
//        System.out.println("收到参数：id="+id+",name="+name);
//        return "success";
//    }
}
